<?php
namespace app\index\controller;

use think\Controller;


class Index extends Controller
{
    //微信支付 - 全部展示
    public function index()
    {
        return $this->fetch();
    }


    //测试首页面
    public function test()
    {
        $num = build_order_no();

        // 生成微信支付二维码
        $result = wxpayQrcode($num,'1234113355',10,'商品描述','1');
        $url2 = $result["code_url"];
        //生成二维码
        $savePath = APP_PATH . '/../Public/qrcode/';
        $webPath = '/qrcode/';
        $qrData = $url2;
        $qrLevel = 'H';
        $qrSize = '8';
        $savePrefix = 'tmc';

        if($filename = createQRcode($savePath, $qrData, $qrLevel, $qrSize, $savePrefix)){
            $pic = $webPath . $filename;
        }

        $this->assign('num',$num);
        $this->assign('pic',$pic);

        return $this->fetch();
    }



    //支付成功
    public function pay_success()
    {
        echo "pay_success";
    }

    //请求页
    public function orderquery()
    {
        if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
            $transaction_id = $_REQUEST["transaction_id"];
            $result=wxpayQuery($transaction_id,'');
            echo $result['trade_state'];
            exit();
        }

        if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
            $out_trade_no = $_REQUEST["out_trade_no"];
            $result=wxpayQuery('',$out_trade_no);
            echo $result['trade_state'];
            exit();
        }

    }

}
